﻿using Grpc.Core;
using GrpcPtlSave;
using System.Threading.Tasks;

namespace PtlSave
{
    /*
     * 数据存储服务结点状态
     */
    #region snippet
    public class GRPCSvr : GrpcPtlSave.SaveGrpc.SaveGrpcBase
    {
        //数据缓存
        private static StoreStatus storeStatus = new StoreStatus();
        private static StoreDetail storeDetail = new StoreDetail();

        /*
         * 获取总体存储汇总
         */
        public override Task<StoreStatus> GetStoreStatus(RequestModel request, ServerCallContext context)
        {
            storeStatus.ConsumCount = ulong.Parse(Program._dataDeal.ConsumCount.ToString());
            storeStatus.StoreCount = ulong.Parse(Program._dataDeal.StoreCount.ToString());
            storeStatus.ConsumRate = ulong.Parse(Program._dataDeal.saveNums.ToString());
            storeStatus.StoreErrCount = ulong.Parse(Program._dataDeal.StoreErrCount.ToString());
            storeStatus.WaitConsumCount = ulong.Parse(Program._dataDeal.waitingNumPre.ToString());
            return Task.FromResult(storeStatus);
        }

        /*
         * 获取写入每个表的数据统计
         */
        public override Task<StoreDetail> GetStoreDetail(RequestModel request, ServerCallContext context)
        {
            storeDetail.StoreStatic.Clear();
            storeDetail.StoreStatic.Add(Program._dataDeal.storeStatics.Values);
            return Task.FromResult(storeDetail);
        }
    }
    #endregion
}
